//
//  XDLMMyViewController.m
//  xindailianmeng
//
//  Created by 许佳奇 on 17/1/17.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDLMMyViewController.h"
#import "AFHTTPSessionManager+POST.h"
#import "UILabel+Extension.h"
#import "UIButton+Extension.h"
#import "XDLMMyCell.h"
#import "ZHRTBasicMethod.h"
#import "UIImageView+WebCache.h"
#import "XDMyInvestmentViewController.h"
#import "XDTradeRecordsViewController.h"
#import "ZDMyVoucherViewController.h"
#import "XDBMyUserInfoViewController.h"
#import "XDMyAchieveViewController.h"
#import "XDUserCenterController.h"
#import "XDToRechargeViewController.h"
#import "ZHRTRequestFailureShowViewOrDetail.h"
#import "XDMessageViewController.h"
#import "XDLMLoginViewController.h"
#import "AppDelegate.h"
#import "XDAssetDetailsViewController.h"
#import "XDMyInviteViewController.h"
@interface XDLMMyViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, weak) UITableView *tableView;

@property (nonatomic, strong)NSArray *myArr;
//2：业务员arr
@property (nonatomic, strong)NSArray *businessArr;
//banpic  : String   banner图url
@property (nonatomic, weak) UIImageView *backgroundimg;
//totalMoney ：账户总资产 double 保留两位小数点
@property (nonatomic, weak) UIButton *propertyBtn;
//avaMoney：可用余额 double 保留两位小数点
@property (nonatomic, weak) UILabel *canUseLb;
//collectProfit：待收收益 double 保留两位小数点
@property (nonatomic, weak) UILabel *profitLb;
/*
 userType： 用户类型  String
 0： 不是内部员工
 1：是内部员工
 2：业务员
 3：离职员工
 （为2的时候是业务员 反之其他都是普通用户）
 */
@property (nonatomic, copy) NSString *userType;

@property (nonatomic, copy) NSAttributedString *totalMoneyAttr;
@property (nonatomic, copy) NSString *canUseStr;

@property (nonatomic, copy) NSString *profitStr;

@property (nonatomic, weak) UIView * errorView;

@property (nonatomic, weak) UIView *progressHUDView;
@end

@implementation XDLMMyViewController

- (NSArray *)myArr {
    if (_myArr == nil) {
        _myArr = @[
  @[@[@"shou",@"我的投资"], @[@"jiaoyi",@"交易明细"]],
  @[@[@"youhuiquan",@"优惠券"], @[@"yaoqing",@"邀请好友"]],
  @[@[@"kefu",@"客服电话 (9:00-18:00)"]]];
    }
    return _myArr;
}
- (NSArray *)businessArr {
    if (_businessArr == nil) {
        _businessArr = @[
  @[@[@"shou",@"我的投资"], @[@"jiaoyi",@"交易明细"]],
  @[@[@"youhuiquan",@"优惠券"]],
  @[@[@"myUser",@"我的客户"],@[@"myAchievement",@"我的业绩"]],
  @[@[@"kefu",@"客服电话 (9:00-18:00)"]]
  ];
    }
    return _businessArr;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self loadData];
    [self navigationBarCof];
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    // 提现 toWithdraw
    [df removeObjectForKey: @"toWithdraw"];
    [df synchronize];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    // 禁用 iOS7 返回手势
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)loadData {
  
    [ZHRTRequestFailureShowViewOrDetail showProgressHUDWithInView:self.progressHUDView type:1];
    NSDictionary * param = @{@"method":@"userCenter"};
    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
        [self.progressHUDView removeFromSuperview];
        
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
            
            [self.errorView removeFromSuperview];
            
            NSString *str = [ZHRTBasicMethod ChangeNumberFormat:[NSString stringWithFormat:@"%.2f",[responseObject[@"result"][@"totalMoney"] floatValue]]];
            NSMutableAttributedString *totalMoneyStr = [[NSMutableAttributedString alloc] initWithString:str ];
            [totalMoneyStr addAttribute:NSFontAttributeName value:kFont_(50) range:NSMakeRange(str.length - 2, 2)];
            [totalMoneyStr addAttribute:NSBaselineOffsetAttributeName value:@(0.36 * (60 - 50)) range:[str rangeOfString:@","]];
              [totalMoneyStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:[str rangeOfString:str]];
            self.totalMoneyAttr = totalMoneyStr;
//            [self.propertyBtn setAttributedTitle:totalMoneyStr forState:UIControlStateNormal];
            
            self.canUseStr = [ZHRTBasicMethod ChangeNumberFormat:[NSString stringWithFormat:@"%.2f",[responseObject[@"result"][@"avaMoney"] floatValue]]];
//            self.canUseLb.text = self.canUseStr;
            
            self.profitStr = [ZHRTBasicMethod ChangeNumberFormat:[NSString stringWithFormat:@"%.2f",[responseObject[@"result"][@"collectProfit"] floatValue]]];
//            self.profitLb.text = self.profitStr;
//
            
//            if ([responseObject[@"result"][@"notReadedMsgCount"] integerValue] != 0) {
//                 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"xinfeng_heig"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick)];
//            }
//            
            NSArray *arr = responseObject[@"result"][@"appMyPicList"];
            for (NSInteger i = 0; i < arr.count; i ++) {
                long result = [self compareDate:[self date] withDate:arr[i][@"startTime"]];
                if (result == -1) {
                    long result = [self compareDate:[self date] withDate:arr[i][@"endTime"]];
                    if (result == 1) {
                    [self.backgroundimg sd_setImageWithURL:[NSURL URLWithString:arr[i][@"banpic"]] placeholderImage:[UIImage imageNamed:@"my_top_bg"] options:SDWebImageRefreshCached];
                    }
                }
               
            }
            
//           self.userType = [self.userType  isEqual: @"2"] ? @"0": @"2";
            self.userType = [responseObject[@"result"][@"userType"] stringValue]; ;
            [self.tableView reloadData];
            
                } else if ([responseObject[@"code"] isEqualToString:@"100054"] ||[responseObject[@"code"] isEqualToString:@"100001"]){ // 用户信息错误
                    XDLMLoginViewController *loginVc = [[XDLMLoginViewController alloc] init];
                    loginVc.hidesBottomBarWhenPushed = YES;
                    loginVc.isTip = YES;
                    NSUserDefaults *df =[NSUserDefaults standardUserDefaults];
                    [df setValue:@"Y" forKey:@"isMine"];
                    [df removeObjectForKey:@"uid"];
                    [df synchronize];
                    XDLMNavigatonController * nav = [[XDLMNavigatonController alloc] initWithRootViewController:loginVc];
                    AppDelegate *delegate =(AppDelegate *) [UIApplication sharedApplication].delegate;
                    [delegate.window.rootViewController presentViewController:nav animated:YES completion:nil];
                    
        } else {

            [ZHRTRequestFailureShowViewOrDetail showViewDetail:responseObject[@"message"] view:self.view];
        }
        [self setNumber];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [self.progressHUDView removeFromSuperview];
        if (!_errorView) {
            
            [self.view addSubview:self.errorView ];
            [ZHRTRequestFailureShowViewOrDetail showRequestFailureForView:_errorView target:self action:@selector(loadData) type:1];
        }
        [self setNumber];
    }];
    
    
    
}
//当前时间
- (NSString *)date {
    NSDate *date = [NSDate date];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    NSString *DateTime = [formatter stringFromDate:date];
    return DateTime;
}
#pragma mark -- 比较时间
-(long)compareDate:(NSString*)date01 withDate:(NSString*)date02{
    int ci;
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    

    NSDate *dt1 = [df dateFromString:date01];
    NSDate *dt2 = [df dateFromString:date02];
    NSComparisonResult result = [dt1 compare:dt2];
    switch (result)
    {
            //date02比date01大
        case NSOrderedAscending: ci=1; break;
            //date02比date01小
        case NSOrderedDescending: ci=-1; break;
            //date02=date01
        case NSOrderedSame: ci=0; break;
        default:
            break;
    }
    return ci;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
}
#pragma mark -- UI setter
- (void)setupUI {
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH - 49) style:UITableViewStyleGrouped];
    self.automaticallyAdjustsScrollViewInsets = NO;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.showsHorizontalScrollIndicator = NO;
    self.tableView = tableView;
    [self.view addSubview:tableView];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 262)];
    tableView.tableHeaderView = view;
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 80)];
    UILabel *tipLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, kScreenW, 15)];
    tipLb.text = @"市场有风险，投资须谨慎";
    tipLb.textColor = kColorRGB(153,153,153);
    tipLb.font = kBaseFont_(10);
    tipLb.textAlignment = NSTextAlignmentCenter;
    [footerView addSubview:tipLb];
    tableView.tableFooterView = footerView;
    
//    背景图
    UIImageView *backgroundimg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_top_bg"]];
    backgroundimg.frame = CGRectMake(0, 0, kScreenW, 209);
    self.backgroundimg = backgroundimg;
    backgroundimg.userInteractionEnabled = YES;
    [view addSubview:backgroundimg];
//    遮罩
    UIImageView *hideImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_top"]];
    hideImg.frame = CGRectMake(0, 0, kScreenW, 209);
    hideImg.userInteractionEnabled = YES;
    [view addSubview:hideImg];

    UIButton *propertyBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 60, kScreenW, 58)];
//    [UILabel lableWithText:@"0.00" textColor:kColorRGB(255, 255, 255) textFont:60 textAlignment:NSTextAlignmentCenter point:CGPointMake(0, 68) width:kScreenW];
//    propertyBtn.frame = CGRectMake(0, 60, kScreenW, 58);
//    propertyBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
   
    propertyBtn.titleLabel.font = kFont_(60);
    propertyBtn.titleLabel.contentMode = UIViewContentModeBottom;
    [propertyBtn setTitle:@"0.00" forState:UIControlStateNormal];
    [propertyBtn setTitleColor:kColorRGB(255, 255, 255) forState:UIControlStateNormal];
    [propertyBtn addTarget:self action:@selector(propertyBtnCkick) forControlEvents:UIControlEventTouchUpInside];
    self.propertyBtn = propertyBtn;
    [hideImg addSubview:propertyBtn];
//    总资产(元)

    UIImage *img = [UIImage imageNamed:@"eye"];
    UILabel *propertyDetalLb = [UILabel lableWithText:@"总资产 (元)" textColor: kMyColor textFont:14 textAlignment:NSTextAlignmentLeft point:CGPointMake(140 * kscaleW, CGRectGetMaxY(propertyBtn.frame)- 2) width:kScreenW];
    [propertyDetalLb sizeToFit];
    propertyDetalLb.frame = CGRectMake((kScreenW - img.size.width - 9 - propertyDetalLb.frame.size.width) * 0.5 , CGRectGetMaxY(propertyBtn.frame) + 8, propertyDetalLb.frame.size.width, propertyDetalLb.frame.size.height);
    [hideImg addSubview:propertyDetalLb];

    UIButton *eyeBtn = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(propertyDetalLb.frame) + 9, CGRectGetMinY(propertyDetalLb.frame) + (propertyDetalLb.frame.size.height - img.size.height) * 0.5, img.size.width,img.size.height)];
    [eyeBtn setBackgroundImage:img forState:UIControlStateNormal];
    [eyeBtn setBackgroundImage:[UIImage imageNamed:@"eyeClose"] forState:UIControlStateSelected];
    [eyeBtn addTarget:self action:@selector(eyeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    eyeBtn.selected = [[[NSUserDefaults standardUserDefaults] valueForKey:@"eyeBtnSelected"] boolValue];
    eyeBtn.alpha = 0.5;
    [hideImg addSubview:eyeBtn];
    
    UILabel *canUseLb = [UILabel lableWithText:@"0.00" textColor:kColorRGB(255, 255, 255) textFont:16 textAlignment:NSTextAlignmentCenter point:CGPointMake(0, 209 - 52 + 10) width:kScreenW * 0.5];
    canUseLb.lineBreakMode = NSLineBreakByTruncatingTail;
    self.canUseLb = canUseLb;
    [hideImg addSubview:canUseLb];

    UILabel *canUseDatalLb = [UILabel lableWithText:@"可用余额" textColor:kMyColor textFont:10 textAlignment:NSTextAlignmentCenter point:CGPointMake(0, CGRectGetMaxY(canUseLb.frame) + 2) width:kScreenW * 0.5];
    [hideImg addSubview:canUseDatalLb];
    
    
    UILabel *profitLb = [UILabel lableWithText:@"0.00" textColor:kColorRGB(255, 255, 255) textFont:16 textAlignment:NSTextAlignmentCenter point:CGPointMake(kScreenW * 0.5, 209 - 52 + 10) width:kScreenW * 0.5];
    profitLb.lineBreakMode = NSLineBreakByTruncatingTail;
    self.profitLb = profitLb;
    [hideImg addSubview:profitLb];
    
    UILabel *profitDatalLb = [UILabel lableWithText:@"待收收益" textColor:kMyColor textFont:10 textAlignment:NSTextAlignmentCenter point:CGPointMake(kScreenW * 0.5, CGRectGetMaxY(canUseLb.frame) + 2) width:kScreenW * 0.5];
    [hideImg addSubview:profitDatalLb];
    
    UIView *carveView1 = [[UIView alloc] initWithFrame:CGRectMake(kScreenW * 0.5, 209 - 52 + 13, 1, 26)];
    carveView1.backgroundColor = kColorRGBA(255, 255,255, 0.2);
    [hideImg addSubview:carveView1];

    UIButton *topupBtn = [UIButton buttonWithFrame:CGRectMake(0,CGRectGetMaxY(backgroundimg.frame), kScreenW * 0.5,view.frame.size.height - backgroundimg.frame.size.height) norImgNamed:@"shou_left" selImgNamed:nil title:@"充值" titleColor:kColorRGB(0, 0, 0) selColor:nil titleFont:17 target:self selector:@selector(topupBtnClick)];
    topupBtn.backgroundColor = kColorRGB(255,255, 255);
    topupBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -2, 0, 0);
    [view addSubview:topupBtn];
    
    
    UIButton *withdrewBtn = [UIButton buttonWithFrame:CGRectMake(kScreenW * 0.5,CGRectGetMaxY(backgroundimg.frame), kScreenW * 0.5,view.frame.size.height - backgroundimg.frame.size.height) norImgNamed:@"shou_right" selImgNamed:nil title:@"提现" titleColor:kColorRGB(0, 0, 0) selColor:nil titleFont:17 target:self selector:@selector(withdrewBtnClick)];
    withdrewBtn.backgroundColor = kColorRGB(255,255,255);
     withdrewBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -2, 0, 0);
    [view addSubview:withdrewBtn];
    
    UIView *carveView2 = [[UIView alloc] initWithFrame:CGRectMake(kScreenW * 0.5, 262 - 28 - 12, 1, 28)];
    carveView2.backgroundColor = kColorRGBA(0, 0, 0, 0.1);
    [view addSubview:carveView2];
    
    
    UIView *carveView3 = [[UIView alloc] initWithFrame:CGRectMake(0, 262, kScreenW, 0.5)];
    carveView3.backgroundColor = kColorRGBA(0, 0, 0, 0.2);
    [view addSubview:carveView3];
    
}



#pragma mark -- navigationBar setter
- (void)navigationBarCof {
    
//    self.title = @"我的";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"transparentNav"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"shezhi"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftItemClick)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"xinfeng_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick)];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

#pragma mark -- tableView delegate  dataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([self.userType isEqualToString:@"2"]) {
        return 4;
    }
    return 3;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([self.userType isEqualToString:@"2"]) {
        if (section == 1 || section == 3 ) {
            return 1;
        }
        return 2;
    }
    if (section == 2 ) {
        return 1;
    }
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *myID = @"myTableViewID";
    XDLMMyCell *cell = [tableView dequeueReusableCellWithIdentifier:myID];
    if (cell == nil) {
        cell = [[XDLMMyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([self.userType isEqualToString:@"2"]) {
        
        [cell cellWithCellArr:self.businessArr indexPath:indexPath];
        return cell;
    }
    [cell cellWithCellArr:self.myArr indexPath:indexPath];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (([self.userType isEqualToString:@"2"] && indexPath.section == 3) || (![self.userType isEqualToString:@"2"] && indexPath.section == 2)) {
        
        NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"400-805-9696"];
        UIWebView *callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
     
    }
    if (indexPath.section == 0 && indexPath.row == 0) {
        XDMyInvestmentViewController *vc = [[XDMyInvestmentViewController alloc] init];
        
        [self.navigationController pushViewController:vc animated:YES];
    } else  if (indexPath.section == 0 && indexPath.row == 1) {
        XDTradeRecordsViewController *vc = [[XDTradeRecordsViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.section == 1 && indexPath.row == 0) {
        
        ZDMyVoucherViewController *myVoucher = [[ZDMyVoucherViewController alloc] init];
        [self.navigationController pushViewController:myVoucher animated:YES];
        
    }else if ([self.userType isEqualToString:@"2"] &&indexPath.section == 2 && indexPath.row == 0) {
        
        XDBMyUserInfoViewController *myUserInfo = [[XDBMyUserInfoViewController alloc] init];
        [self.navigationController pushViewController:myUserInfo animated:YES];
        
    }else if ([self.userType isEqualToString:@"2"] &&indexPath.section == 2 && indexPath.row == 1) {
        
        XDMyAchieveViewController *myAchieve = [[XDMyAchieveViewController alloc] init];
        [self.navigationController pushViewController:myAchieve animated:YES];
        
    }else if (![self.userType isEqualToString:@"2"] &&indexPath.section == 1 && indexPath.row == 1) {
#warning yaoqing
        XDMyInviteViewController *myInvite = [[XDMyInviteViewController alloc] init];
        [self.navigationController pushViewController:myInvite animated:YES];
        
    }
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint offset = scrollView.contentOffset;
    if (offset.y <= 0) {
        offset.y = 0;
    }
   
    scrollView.contentOffset = offset;
}

//设置
- (void)leftItemClick {
    
    XDUserCenterController *userCenter = [[XDUserCenterController alloc] init];
    
    [self.navigationController pushViewController:userCenter animated:YES];

}
//消息
- (void)rightItemClick {
    
     NSLog(@"消息");
    XDMessageViewController *message = [[XDMessageViewController alloc] init];
    [self.navigationController pushViewController:message animated:YES];
    
}
// 点击查看总资产
- (void)eyeBtnClick:(UIButton *)eyeBtn {
    
    eyeBtn.selected = !eyeBtn.selected;
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    [df setBool:eyeBtn.selected forKey:@"eyeBtnSelected"];
    [df synchronize];
    [self setNumber];
}

- (void)setNumber {
    
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    BOOL sel = [[df valueForKey:@"eyeBtnSelected"] boolValue];
    if (sel) {
        [self.propertyBtn setAttributedTitle:[[NSAttributedString alloc] initWithString:@"***" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]  forState:UIControlStateNormal];
        self.canUseLb.text = @"***";
        
        self.profitLb.text = @"***";
    } else {
        if (self.totalMoneyAttr) {
          
            [self.propertyBtn setAttributedTitle:self.totalMoneyAttr forState:UIControlStateNormal];
            
        } else {
            
            NSString *str = @"0.00";
            NSMutableAttributedString *totalMoneyStr = [[NSMutableAttributedString alloc] initWithString:str ];
            [totalMoneyStr addAttribute:NSFontAttributeName value:kFont_(50) range:NSMakeRange(str.length - 2, 2)];
            [totalMoneyStr addAttribute:NSBaselineOffsetAttributeName value:@(0.36 * (60 - 50)) range:[str rangeOfString:@","]];
            [totalMoneyStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:[str rangeOfString:str]];
             [self.propertyBtn setAttributedTitle:totalMoneyStr forState:UIControlStateNormal];
        }
        if (self.canUseStr) {
            self.canUseLb.text = self.canUseStr;
        } else {
            self.canUseLb.text = @"0.00";
        }
        
        if (self.profitStr) {
            self.profitLb.text = self.profitStr;
        } else {
            self.profitLb.text = @"0.00";
        }

    }
    
}

- (void)topupBtnClick {
    
    NSLog(@"充值");
    
    XDToRechargeViewController *toRecharge = [[XDToRechargeViewController alloc] init];
    
    [self.navigationController pushViewController:toRecharge animated:YES];
    
    
}

- (void)withdrewBtnClick {
    
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
// 提现 toWithdraw
    [df setValue:@"Y" forKey:@"toWithdraw"];
    [df synchronize];
    
    NSLog(@"提现");
    XDToRechargeViewController *toRecharge = [[XDToRechargeViewController alloc] init];
    
    [self.navigationController pushViewController:toRecharge animated:YES];
    
}

- (void)propertyBtnCkick {
    
    NSLog(@"总资产");
    
    XDAssetDetailsViewController *asset = [[XDAssetDetailsViewController alloc] init];
    [self.navigationController pushViewController:asset animated:YES];
    
}

- (UIView *)errorView {
    if (_errorView == nil) {
        UIView *view = [[UIView alloc] initWithFrame:kScreenB];
        _errorView = view;
        [self.view addSubview:view];
    }
    return _errorView;
}
- (UIView *)progressHUDView {
    if (_progressHUDView == nil) {
        UIView *view = [[UIView alloc] initWithFrame:kScreenB];
        _progressHUDView = view;
        [self.view addSubview:view];
    }
    return _progressHUDView;
}

@end
